package UIComponent 
{
	import flash.events.FocusEvent;
	import flash.filters.GlowFilter;
	import flash.geom.Rectangle;
	import flash.system.Capabilities;
	import flash.system.IME;
	import flash.text.TextField;
	import flash.text.TextFieldType;
	import flash.text.TextFormat;
	import flash.text.TextFormatAlign;
	import game.manager.LanguageManager;
	
	/**
	 * ...
	 * @author gcxk721
	 */
	public class CustomTextfield extends TextField 
	{
		private static var _glowFilter:GlowFilter = new GlowFilter(0, 1, 2, 2, 4);
		
		private var _filterArray:Array;
        private var _useHandCursor:Boolean;
        private var _textFormat:TextFormat;
        private var _isUnderLine:Boolean;
        private var _tempHtmLText:String;
		
		public function CustomTextfield(addFilter : Boolean = true)
		{
            super();
            if (addFilter)
			{
                this._filterArray = [_glowFilter];
                filters = this._filterArray;
            }
            this._textFormat = new TextFormat();
            this._textFormat.align = TextFormatAlign.LEFT;
            this._textFormat.color = 0xD9D5BB;
            this._textFormat.size = 12;
            this._textFormat.font = LanguageManager.fontType;
            defaultTextFormat = this._textFormat;
            height = 21;
            this._isUnderLine = false;
        }
        override public function getCharBoundaries(charIndex : int) : Rectangle
		{
            var h : Number;
            var rect : Rectangle = this.getCharBoundaries2(_arg1);
            if (_local2 == null)
			{
                h = height;
                height = textHeight;
                rect = this.getCharBoundaries2(_arg1);
                height = h;
            };
            return rect;
        }
		
        public function set size(value : Object):void
		{
            this._textFormat.size = value;
            defaultTextFormat = this._textFormat;
            text = text;
        }
		
        public function set align(value : String):void
		{
            this._textFormat.align = value;
            defaultTextFormat = this._textFormat;
            text = text;
        }
		
        public function set leading(value : Object):void
		{
            this._textFormat.leading = value;
            defaultTextFormat = this._textFormat;
            text = text;
        }
		
        public function set bold(value : Object):void
		{
            this._textFormat.bold = value;
            defaultTextFormat = this._textFormat;
            text = text;
        }
		
        public function set isUnderLine(value : Boolean):void
		{
            this._isUnderLine = value;
        }
		
        public function set textBorderColor(color : uint):void
		{
            this._glowFilter.color = color;
            filters = this._filterArray;
        }
		
        public function set underline(value :Object):void
		{
            this._textFormat.underline = value;
            defaultTextFormat = this._textFormat;
            text = text;
        }
		
        public function set textBorderAlpha(value : Number):void
		{
            this._glowFilter.alpha = value;
            filters = this._filterArray;
        }
		
        private function focusOutHandler(evt : FocusEvent):void
		{
            if (Capabilities.hasIME == true)
			{
                IME.enabled = false;
            }
        }
		
        public function get inner():Boolean
		{
            return this._glowFilter.inner;
        }
		
        public function set font(value : String):void
		{
            this._textFormat.font = value;
            defaultTextFormat = this._textFormat;
            text = text;
        }
		
        public function set indent(value : Object):void
		{
            this._textFormat.indent = value;
            defaultTextFormat = this._textFormat;
            text = text;
        }
		
        public function get isUnderLine():Boolean
		{
            return this._isUnderLine;
        }
		
        public function dispose():void
		{
			
        }
		
        public function set color(value : Object):void
		{
            this._textFormat.color = value;
            defaultTextFormat = this._textFormat;
            text = text;
        }
		
        public function set inner(value : Boolean):void
		{
            this._glowFilter.inner = value;
            filters = this._filterArray;
        }
		
        private function focusInHandler(evt : FocusEvent):void
		{
            if (type == TextFieldType.INPUT)
			{
                if (Capabilities.hasIME == true)
				{
                    IME.enabled = true;
                }
            }
        }
		
        override public function set htmlText(str : String):void
		{
            defaultTextFormat = defaultTextFormat;
            super.htmlText = str;
        }
		
        public function set textBorderBlurY(value : Number):void
		{
            this._glowFilter.blurY = value;
            filters = this._filterArray;
        }
		
        public function set textBorderStrength(value :Number):void 
		{
            this._glowFilter.strength = value;
            filters = this._filterArray;
        }
		
        public function set textBorderBlurX(value:Number):void
		{
            this._glowFilter.blurX = value;
            filters = this._filterArray;
        }
		
        public function set letterSpacing(value:Object):void
		{
            this._textFormat.letterSpacing = value;
            defaultTextFormat = this._textFormat;
            text = text;
        }
		
        override public function set type(value:String):void
		{
            super.type = value;
            if (TextFieldType.INPUT == value)
			{
                addEventListener(FocusEvent.FOCUS_IN, this.focusInHandler);
                addEventListener(FocusEvent.FOCUS_OUT, this.focusOutHandler);
            }
        }
		
        public function get letterSpacing():Object
		{
            return this._textFormat.letterSpacing;
        }
		
        private function getCharBoundaries2(charIndex:int):Rectangle
		{
            var h:Number;
            var index : int;
            var v : int;
            var rect : Rectangle = super.getCharBoundaries(charIndex);
            if (rect == null)
			{
                h = height;
                height = textHeight;
                index = getLineIndexOfChar(charIndex);
                if (bottomScrollV < index)
				{
                    v = scrollV;
                    scrollV = index;
                    rect = super.getCharBoundaries(charIndex);
                    scrollV = v;
                }
                height = h;
            }
            return rect;
        }
		
	}

}